package com.microcdyUser.controller;
import com.microcdy.sys.pojo.SysLogininfor;
import com.microcdyUser.service.SysLogininforService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/****
 * @Author:cdy
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/sysLogininfor")
@CrossOrigin
public class SysLogininforController {

    @Autowired
    private SysLogininforService sysLogininforService;

    /***
     * SysLogininfor分页条件搜索实现
     * @param sysLogininfor
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  SysLogininfor sysLogininfor, @PathVariable  int page, @PathVariable  int size){
        //调用SysLogininforService实现分页条件查询SysLogininfor
        PageInfo<SysLogininfor> pageInfo = sysLogininforService.findPage(sysLogininfor, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SysLogininfor分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SysLogininforService实现分页查询SysLogininfor
        PageInfo<SysLogininfor> pageInfo = sysLogininforService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sysLogininfor
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<SysLogininfor>> findList(@RequestBody(required = false)  SysLogininfor sysLogininfor){
        //调用SysLogininforService实现条件查询SysLogininfor
        List<SysLogininfor> list = sysLogininforService.findList(sysLogininfor);
        return new Result<List<SysLogininfor>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用SysLogininforService实现根据主键删除
        sysLogininforService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SysLogininfor数据
     * @param sysLogininfor
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  SysLogininfor sysLogininfor,@PathVariable Long id){
        //设置主键值
        sysLogininfor.setInfoId(id);
        //调用SysLogininforService实现修改SysLogininfor
        sysLogininforService.update(sysLogininfor);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SysLogininfor数据
     * @param sysLogininfor
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   SysLogininfor sysLogininfor){
        //调用SysLogininforService实现添加SysLogininfor
        sysLogininforService.add(sysLogininfor);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SysLogininfor数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SysLogininfor> findById(@PathVariable Long id){
        //调用SysLogininforService实现根据主键查询SysLogininfor
        SysLogininfor sysLogininfor = sysLogininforService.findById(id);
        return new Result<SysLogininfor>(true,StatusCode.OK,"查询成功",sysLogininfor);
    }

    /***
     * 查询SysLogininfor全部数据
     * @return
     */
    @GetMapping
    public Result<List<SysLogininfor>> findAll(){
        //调用SysLogininforService实现查询所有SysLogininfor
        List<SysLogininfor> list = sysLogininforService.findAll();
        return new Result<List<SysLogininfor>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
